/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.signallight.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.signallight.entity.TSignalLight;
import com.thinkgem.jeesite.modules.signallight.service.TSignalLightService;

/**
 * 信号灯与停车区关联Controller
 * @author Leon
 * @version 2019-04-12
 */
@Controller
@RequestMapping(value = "${adminPath}/signallight/tSignalLight")
public class TSignalLightController extends BaseController {

	@Autowired
	private TSignalLightService tSignalLightService;
	
	@ModelAttribute
	public TSignalLight get(@RequestParam(required=false) String id) {
		TSignalLight entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tSignalLightService.get(id);
		}
		if (entity == null){
			entity = new TSignalLight();
		}
		return entity;
	}
	
	@RequiresPermissions("signallight:tSignalLight:view")
	@RequestMapping(value = {"list", ""})
	public String list(TSignalLight tSignalLight, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TSignalLight> page = tSignalLightService.findPage(new Page<TSignalLight>(request, response), tSignalLight); 
		model.addAttribute("page", page);
		return "modules/signallight/tSignalLightList";
	}

	@RequiresPermissions("signallight:tSignalLight:view")
	@RequestMapping(value = "form")
	public String form(TSignalLight tSignalLight, Model model) {
		model.addAttribute("tSignalLight", tSignalLight);
		return "modules/signallight/tSignalLightForm";
	}

	@RequiresPermissions("signallight:tSignalLight:edit")
	@RequestMapping(value = "save")
	public String save(TSignalLight tSignalLight, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tSignalLight)){
			return form(tSignalLight, model);
		}
		tSignalLightService.save(tSignalLight);
		addMessage(redirectAttributes, "保存信号灯与停车区关联成功");
		return "redirect:"+Global.getAdminPath()+"/signallight/tSignalLight/?repage";
	}
	
	@RequiresPermissions("signallight:tSignalLight:edit")
	@RequestMapping(value = "delete")
	public String delete(TSignalLight tSignalLight, RedirectAttributes redirectAttributes) {
		tSignalLightService.delete(tSignalLight);
		addMessage(redirectAttributes, "删除信号灯与停车区关联成功");
		return "redirect:"+Global.getAdminPath()+"/signallight/tSignalLight/?repage";
	}

}